{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python 语言快速概览 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "本节将简单地介绍Python语言的语法，不涉及具体编程应用的内容。对于完全不熟悉Python语言的同学，还需要适当额外补充相应的知识和练习。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面将介绍以下主题：\n",
    "* 数据基本类型，表达式，变量及其赋值\n",
    "* 基本数据结构\n",
    "* 控制语句\n",
    "* 函数和对象"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据基本类型，表达式，变量及其赋值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "Python中的所有数据都视为一个对象object，不管是简单的数字还是其他复杂的数据结构都用对象来表示。常用的内置数据类型为："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "* 整型 Intergers： 有符号整数\n",
    "* 布尔型 booleans： True 或 False，等价于1或0，也可以算作整型\n",
    "* 浮点型 Floats： 双精度浮点数\n",
    "* 复数型 Complex： 复数，由一对浮点数组成"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "interger_number = 583\n",
    "boolean_var = True\n",
    "real_number = 1.3\n",
    "scientific_notation = 5.2e-13\n",
    "complex_number = 3+5.4j\n",
    "another_complex_number = complex(4.3, 2.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python是弱类型脚本语言，可以实现类型自动推导，大部分情况下不需要显式指定类型。Python自带的数据类型运算效率比较低， 后面将会介绍如何使用 `Numpy` 进行高效的数值运算。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "上面的式子左端就是单变量的名称，右边是单变量所存储的值。也可以多变量同时进行赋值："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "interger_number, boolean_var, real_number = 583, True, 1.3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "所以，在Python中，可以使用以下的技巧交换两个变量的值："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`a, b = b ,a` "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2)\n"
     ]
    }
   ],
   "source": [
    "a=1\n",
    "b=2\n",
    "print(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 1)\n"
     ]
    }
   ],
   "source": [
    "a, b = b ,a\n",
    "print(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
